<template>
  <!-- 放置一个图标 -->
  <div>
    <!-- 三元表达式  来控制图标的显示 -->
    <svg-icon
      :icon-class="isFullScreen?'exit-fullscreen':'fullscreen'"
      class="fullscreen"
      @click.native="toggleFullScreen"
    />
  </div>
</template>

<script>
import ScreenFull from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      isFullScreen: false
    }
  },
  methods: {
    // 点击图标
    toggleFullScreen() {
      // 判断浏览器是否支持全屏
      if (ScreenFull.isEnabled) {
        // 更改变量，用来控制图标
        this.isFullScreen = !this.isFullScreen
        // 在全屏和正常直接切换
        ScreenFull.toggle()
      } else {
        // 如果不支持就弹窗
        this.$message.warning('亲，您的浏览器不支持大屏，请升级浏览器')
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.fullscreen {
  margin-right: 10;
  width: 20px;
  height: 20px;
  fill: #fff;
  cursor: pointer;
}
</style>
